import fang from '../../models/Fang';
Page({
  data: {
    fangs: [],
    page: 1,
    kw: '',
    topNum: 0,
    showTop: true,
  },
  onLoad(options) {

  },
  dosearch(evt) {
    let kw = evt.detail.value;
    let page = this.data.page;

    fang.search(kw, page).then( ret => {
      if (ret.data.data.data.length > 0) {
        this.setData({
          fangs: [ ...this.data.fangs, ...ret.data.data.data],
          page: ++page,
          kw
        })
      }
    });
  },
  getMore(){
    let kw = this.data.kw;
    let page = this.data.page;

    fang.search(kw, page).then( ret => {
      if (ret.data.data.data.length > 0) {
        this.setData({
          fangs: [ ...this.data.fangs, ...ret.data.data.data],
          page: ++page,
          kw
        })
      }
    });
  },
  scrollTop(evt) {
    let scrollTop = evt.detail.scrollTop;
    
    let showTop = true;

    if (scrollTop >= 200) {
      showTop = false;
    }

    this.setData({ showTop });
  },
  goTo() {
    this.setData({
      topNum: 0
    })
  }
})